<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>Jumper documentation</title>
    <link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>Jumper</h1>

<ul>
  <li><a href="../index.html">Index</a></li>
</ul>



<h2>Examples</h2>
<ul>
  <li><strong>annotatedpathing.lua</strong></li>
  <li><a href="../examples/customheuristics.lua.html">customheuristics.lua</a></li>
  <li><a href="../examples/makeclearance.lua.html">makeclearance.lua</a></li>
  <li><a href="../examples/simpleexample.lua.html">simpleexample.lua</a></li>
</ul>
<h2>Modules</h2>
<ul>
  <li><a href="../modules/core.bheap.html">core.bheap</a></li>
  <li><a href="../modules/core.heuristics.html">core.heuristics</a></li>
  <li><a href="../modules/core.node.html">core.node</a></li>
  <li><a href="../modules/core.path.html">core.path</a></li>
  <li><a href="../modules/grid.html">grid</a></li>
  <li><a href="../modules/pathfinder.html">pathfinder</a></li>
</ul>

</div>

<div id="content">

<h1>Example <code>annotatedpathing.lua</code></h1>

    <pre>
<span class="comment">-- Tests sample for clearance metrics calculation
</span><span class="comment">-- See Figure 10 at http://aigamedev.com/open/tutorial/clearance-based-pathfinding/
</span><span class="comment">-- Jump Point Search still has some flaws with clearance based pathfinding
</span>
<span class="keyword">local</span> Grid = <span class="global">require</span> <span class="string">'jumper.grid'</span>
<span class="keyword">local</span> PF = <span class="global">require</span> <span class="string">'jumper.pathfinder'</span>
<span class="keyword">local</span> map = {
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">2</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">2</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">2</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">2</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">2</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>}
}
<span class="keyword">local</span> grid = Grid(map)
<span class="keyword">local</span> walkable = <span class="keyword">function</span>(v) <span class="keyword">return</span> v~=<span class="number">2</span> <span class="keyword">end</span>
<span class="keyword">local</span> finder = PF(grid, <span class="string">'ASTAR'</span>,walkable)
finder:annotateGrid()
<span class="keyword">local</span> finderNames = PF:getFinders()

<span class="keyword">local</span> sx, sy = <span class="number">1</span>,<span class="number">1</span>
<span class="keyword">local</span> ex, ey = <span class="number">9</span>,<span class="number">9</span>
<span class="keyword">local</span> agent_size = <span class="number">2</span>

<span class="keyword">for</span> i = <span class="number">1</span>,#finderNames <span class="keyword">do</span>
	finder:setFinder(finderNames[i])
	<span class="keyword">local</span> path = finder:getPath(sx, sy, ex, ey, agent_size)
	<span class="global">print</span>((<span class="string">'Algorithm used: %s - Path %s'</span>)
		:format(finder:getFinder(), path <span class="keyword">and</span> <span class="string">'found'</span> <span class="keyword">or</span> <span class="string">'not found'</span>))
	<span class="keyword">if</span> path <span class="keyword">then</span>
		<span class="keyword">for</span> node, count <span class="keyword">in</span> path:nodes() <span class="keyword">do</span>
			<span class="global">print</span>((<span class="string">'  Step %d. (%d,%d)'</span>)
				:format(count, node:getPos()))
		<span class="keyword">end</span>
	<span class="keyword">end</span>
<span class="keyword">end</span></pre>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.2</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
